/*oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO

Authors: Nitay Megides
		 Rachel Banino

Project: Exercise 1

Using: LinkedList.h
	   General.h
	   Hw1Types.h

Description:
A List, based on LinkedList, that contains and manages the different 
users in the system. Each list node has a pointer to TUser, which contains the 
inforamtion about the relevant user
oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO*/

#define _CRT_SECURE_NO_WARNINGS
#include "UserList.h"
#include <stdlib.h>
#include <string.h>



// The local list pointer
static PList list;


BOOL InitializeUserList()
{
	list = InitializeList();
	return (BOOL)(list != NULL);
}

BOOL AddUser(const TUserID ID, const char* Name, const char* Nickname)
{
	PUser user = (PUser)malloc(sizeof(TUser));

	user->ID = ID;
	strcpy(user->Name, Name);	
	strcpy(user->Nickname, Nickname);	

	return ((PUser)AddValue(list, user) == user);
}

PUser GetUser(const TUserID ID)
{
	PListItem item = list->Anchor;
	
	while (item != NULL)
	{
		if (((PUser)item->Value)->ID == ID)
			return ((PUser)item->Value);

		item = item->NextItem;
	}

	return NULL;
}

void FreeUserList()
{
	FreeList(list);
}
